package com.googlecode.connectlet.crypto.stream;

import com.googlecode.connectlet.crypto.cipher.Encipheror;
import com.googlecode.connectlet.util.Bytes;

public abstract class FeedbackCipher extends StreamCipher {
	private static final long serialVersionUID = 1L;

	private byte[] iv;

	protected Encipheror cipher;
	protected int blockSize, blockOffset = 0;
	protected byte[] block;

	protected FeedbackCipher(Encipheror cipher, byte[] iv) {
		this.cipher = cipher;
		blockSize = cipher.getBlockSize();
		this.iv = Bytes.left(iv, blockSize);
		block = new byte[blockSize];
		reset();
	}

	public void setCipher(Encipheror cipher) {
		this.cipher = cipher;
	}

	@Override
	public void reset() {
		cipher.encrypt(iv, 0, block, 0);
	}
}